import time

from numpy import ravel
from sklearn import tree
from data import loadDataFromMat
def runDecisionTree(dataName='banana'):
    data=loadDataFromMat(dataName)
    X = data[0]
    y = ravel(data[1])
    num = y.shape[0]
    trainnum = num // 10 * 8
    start = time.clock()
    clf = tree.DecisionTreeClassifier()
    # y2=clf.predict(X)
    clf.fit(X[:trainnum], y[:trainnum])
    s = clf.score(X, y)
    # print((1 - s) * 100)
    end = time.clock()
    return end - start, (1 - s) * 100
# print('DecisionTree',end=',')
# for dataname in ['banana', 'breast_cancer', 'diabetis', 'flare_solar', 'german', 'heart', 'image', 'ringnorm', 'splice', 'thyroid',
#      'titanic', 'twonorm', 'waveform']:
#     runDecisionTree(dataname)
# runDecisionTree('titanic')
